package com.eedi.framework.dept.dal.mapper;

import com.eedi.framework.common.enums.CommonStatusEnum;
import com.eedi.framework.mybatis.core.mapper.BaseMapperX;
import com.eedi.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.eedi.framework.dept.controller.sys.vo.SysDeptListReq;
import com.eedi.framework.dept.dal.dataobject.SysDeptDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

@Mapper
public interface SysDeptMapper extends BaseMapperX<SysDeptDO> {

    default List<SysDeptDO> selectList(SysDeptListReq reqVO) {
        return selectList(new LambdaQueryWrapperX<SysDeptDO>()
                .likeIfPresent(SysDeptDO::getSysDeptName, reqVO.getSysDeptName())
                .eqIfPresent(SysDeptDO::getSysDeptStatus, reqVO.getSysDeptStatus()));
    }

    default void updateStatusBySysDeptId(String sysDeptId, CommonStatusEnum sysDeptStatus) {
        update(new SysDeptDO().setSysDeptStatus(sysDeptStatus), new LambdaQueryWrapperX<SysDeptDO>()
                .eq(SysDeptDO::getSysDeptId, sysDeptId));
    }

    default SysDeptDO selectByParentIdAndName(String parentSysDeptId, String sysDeptName) {
        return selectOne(SysDeptDO::getParentSysDeptId, parentSysDeptId, SysDeptDO::getParentSysDeptId, sysDeptName);
    }

    default Long selectCountByParentId(String parentSysDeptId) {
        return selectCount(SysDeptDO::getParentSysDeptId, parentSysDeptId);
    }

    default List<SysDeptDO> selectListByParentId(Collection<String> parentSysDeptIds) {
        return selectList(SysDeptDO::getParentSysDeptId, parentSysDeptIds);
    }

}
